package com.itheima.controller;

import com.itheima.health.dto.CheckGroupDTO;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.service.CheckGroupService;
import com.itheima.health.service.CheckItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

/**
 * 生成接口注解
 * @Api
 * @ApiOperation
 * @ApiImplicitParams
 * @ApiImplicitParam
 */
@RestController
@Api(tags = "检查组管理开发")  // 作用在类上
public class CheckGroupController {

    @Reference
    private CheckGroupService checkGroupService;

    //检查组修改数据回显
    @GetMapping("checkgroup/findCheckItemInfoByGroupId/{gid}")
    public Result findCheckItemInfoByGroupId(@PathVariable("gid")int gid){
        return new Result(checkGroupService.findCheckItemInfoByGroupId(gid));
    }

    @PostMapping("checkgroup/findPage")
    @ApiOperation(value = "分页查询",notes = "根据客户端请求，完成分页查询")//   添加业务方法上
    @ApiImplicitParams({
            @ApiImplicitParam(name="currentPage",value="当前分页页码",required=true,paramType="form",dataType="Integer"),
            @ApiImplicitParam(name="pageSize",value="每页显示记录数",required=true,paramType="form",dataType="Integer"),
            @ApiImplicitParam(name="queryString",value="查询条件",required=false,paramType="form",dataType="String")
    })
    public Result findPage(@RequestBody QueryPageBean queryPageBean){

        return new Result(checkGroupService.findPage(queryPageBean)); //   total  +  List
    }


    //新建检查组提交
    @PostMapping("checkgroup/add")
    public Result add(@RequestBody CheckGroupDTO checkGroupDTO) {
        return new Result(checkGroupService.saveCheckGroupInfo(checkGroupDTO));
    }

    //逻辑删除
    @DeleteMapping("checkgroup/delectCheckGroupById/{id}")
    public Result delectCheckGroupById(@PathVariable("id") int id){
        return new Result(checkGroupService.updateCheckGroupById(id));
    }

    //查询所有检查组
    @GetMapping("checkgroup/findAll")
    public Result findAll(){
        return new Result(checkGroupService.list());
    }
}








